﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using DeVetma.admin.classes;
using DeVetma.admin.models.database;
using DeVetma.admin.models.managers;
using DeVetma.admin.models.database.metadata;

namespace DeVetma.admin.models.entities
{
    [Entity(table = "Clothes")]
    public class Clothes
    {
        [EntityField(column="cID", keyField = true)]
        public string cID { get; set; }

        [EntityField(column = "cDescription", keyField = false)]
	    public string cDescription { get; set; }

        [EntityField(column = "cMaterial", keyField = false)]
	    public string cMaterial { get; set; }

        [EntityField(column = "cType", keyField = false)]
	    public string cType { get; set; }

        [EntityField(column = "cColor", keyField = false)]
	    public string cColor { get; set; }

        [EntityField(column = "cShoulder", keyField = false)]
	    public string cShoulder { get; set; }

        [EntityField(column = "cWaist", keyField = false)]
	    public string cWaist { get; set; }

        [EntityField(column = "cHips", keyField = false)]
	    public string cHips { get; set; }

        [EntityField(column = "cLength", keyField = false)]
        public string cLength { get; set; }

        [EntityField(column = "cQuanOnHand", keyField = false)]
        public int cQuanOnHand { get; set; }

        [EntityField(column = "cCost", keyField = false)]
	    public decimal cCost { get; set; }

        [EntityField(column = "cSelling", keyField = false)]
	    public decimal cSelling { get; set; }

        [EntityField(column = "cModelImg", keyField = false)]
	    public string cModelImg { get; set; }

        [EntityField(column = "cViewImg", keyField = false)]
	    public string cViewImg { get; set; }

        [EntityField(column = "cTryImg", keyField = false)]
	    public string cTryImg { get; set; }

        [EntityField(column = "cPic1", keyField = false)]
	    public string cPic1 { get; set; }

        [EntityField(column = "cPic2", keyField = false)]
	    public string cPic2 { get; set; }
    
        [EntityField(column = "cPic3", keyField = false)]
	    public string cPic3 { get; set; }

        [EntityField(column = "cStatus", keyField = false)]
        public string cStatus { get; set; }

        public bool isAvailable { get { return cStatus == status(ClothesStatus.Available); } }
        public bool isSoldout { get { return cStatus == status(ClothesStatus.Soldout); } }
        public bool isDeleted { get { return cStatus == status(ClothesStatus.Deleted); } }

        public enum ClothesType { WomanTops = 0, WomanSkirts, WomanShorts, WomanDress,
            ManShirts, ManShorts, ManTrousers }
        public enum ClothesStatus { Available = 0, Soldout, Deleted }
        private static string[] statuses = new string[] { "available", "soldout", "deleted" };

        public void addStock(int qty)
        {
            ClothesManager cm = new ClothesManager();
            this.cQuanOnHand += qty;

            if (cStatus == status(ClothesStatus.Soldout))
                cStatus = status(ClothesStatus.Available);

            cm.update(this);
        }

        public void retrieveStock(int qty)
        {
            ClothesManager cm = new ClothesManager();
            this.cQuanOnHand -= qty;

            if (this.cQuanOnHand <= 0)
                cStatus = status(ClothesStatus.Soldout);

            cm.update(this);
        }

        public bool delete()
        {
            if (cStatus == status(ClothesStatus.Soldout))
                return false;

            cStatus = status(ClothesStatus.Deleted);

            return true;
        }

        public string status(ClothesStatus stat)
        {
            return statuses[(int)stat];
        }

        public string type(ClothesType typ)
        {
            return "" + ((int)typ);
        }

        public override bool Equals(object obj)
        {
            if (obj is Clothes && this.cID == ((Clothes)obj).cID)
                return true;

            return false;
        }
    }
}